package controller;

import base.Session;
import dao.*;
import model.Manager;
import model.Student;

public class Login {
	public static int checkLogin(String username, String password) {
		// 学生端
		if ("student".equals(Session.idStatus)) {
			Student student = StudentDao.getStudent(username);
			if (password.equals(student.getPassword())) {
				return -2;
			} else {
				return 0;
			}
		}
		//
		if ("manager".equals(Session.idStatus)) {
			Manager manager = ManagerDao.getManager(username);
			if (password.equals(manager.getT_password())) {
				if ("1".equals(manager.getIssuper())) {
					// 管理员
					return 1;
				}
			} else {
				return 0;
			}
		}
		if ("teacher".equals(Session.idStatus)) {
			Manager manager = ManagerDao.getManager(username);
			if (password.equals(manager.getT_password())) {
				return -1;
			} else {
				return 0;
			}
		}

		return 0;
	}
}
